package leetcode.biweekly.week79;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//Solution2Test
public class Solution2 {

	// Solution2Test

	public String largestWordCount(String[] messages, String[] senders) {
		int len = senders.length;
		Map<String, Integer> cnts = new HashMap<>();
		int max = Integer.MIN_VALUE;
		List<String> names = new ArrayList<>();
		for (int i = 0; i < senders.length; i++) {
			String[] msg = messages[i].split(" ");
			String name = senders[i];
			int cur = cnts.getOrDefault(name, 0) + msg.length;
			cnts.put(name, cur);
			if (cur > max) {
				names = new ArrayList<>();
				names.add(name);
				max = cur;
			} else if (cur == max) {
				names.add(name);
			}
		}
		Collections.sort(names);
		return names.get(names.size() - 1);

	}

}
